package edu.scau.mis.pos.controller;

import edu.scau.mis.core.annotation.RequestLog;
import edu.scau.mis.core.enums.BusinessType;
import edu.scau.mis.pos.domain.VipPackage;
import edu.scau.mis.pos.service.IVipPackageService;
import edu.scau.mis.core.domain.AjaxResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
 * (VipPackage)表控制层
 *
 * @author CJW
 * @since 2024-04-18 17:39:39
 */
@RestController
@RequestMapping("vipPackage")
public class VipPackageController {
    /**
     * 服务对象
     */
    @Autowired
    private IVipPackageService vipPackageService;

    /**
     * 查询数据列表
     *
     * @param vipPackage 筛选条件
     * @return 查询结果
     */
    @RequestLog(title = "查询数据列表",businessType = BusinessType.GET)
    @GetMapping("/list")
    @ApiOperation("查询数据列表")
    public AjaxResult list(VipPackage vipPackage) {
        List<VipPackage> list = vipPackageService.selectList(vipPackage);
        return AjaxResult.success(list);
    }
    
    /**
     * 分页查询数据列表
     *
     * @param vipPackage 筛选条件
     * @return 查询结果
     */
    @RequestLog(title = "分页查询数据",businessType = BusinessType.GET)
    @GetMapping("/page")
    @ApiOperation("分页查询数据列表")
    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, VipPackage vipPackage) {
        PageHelper.startPage(pageNum,pageSize);
        List<VipPackage> list = this.vipPackageService.selectList(vipPackage);
        PageInfo<List> pageInfo = new PageInfo(list);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestLog(title = "通过主键查询单条数据",businessType = BusinessType.GET)
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    public AjaxResult getById(@PathVariable("id") Long id) {
        return AjaxResult.success(this.vipPackageService.selectById(id));
    }

    /**
     * 新增数据
     *
     * @param vipPackage 实体
     * @return 新增结果
     */
    @RequestLog(title = "新增数据",businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增数据")
    public AjaxResult add(@RequestBody VipPackage vipPackage) {
        return AjaxResult.success(this.vipPackageService.insert(vipPackage));
    }

    /**
     * 编辑数据
     *
     * @param vipPackage 实体
     * @return 编辑结果
     */
    @RequestLog(title = "编辑数据",businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("编辑数据")
    public AjaxResult edit(@RequestBody VipPackage vipPackage) {
        return AjaxResult.success(this.vipPackageService.update(vipPackage));
    }

    /**
     * 批量删除数据
     *
     * @param ids 主键
     * @return 删除是否成功
     */
    @RequestLog(title = "批量删除数据",businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("批量删除数据")
    public AjaxResult deleteById(@PathVariable Long[] ids) {
        int rows = vipPackageService.deleteByIds(ids);
        return rows > 0 ? AjaxResult.success("批量删除成功") : AjaxResult.error("批量删除失败");
    }
}
